package com.yx.fsysserver.common.result;

import com.github.pagehelper.Page;

import java.io.Serializable;
import java.util.List;

/**
 * Created by lichagnfeng on 2017/2/28.
 */
public class JsonPageResult<T> extends JsonListResult implements Serializable {

    private static final long serialVersionUID = 1L;
    private  long total; // 总条数。
    private  int pageSize;  // 每页数量。
    private  int paginations; // 总页码。
    private  int pageNo;   // 当前页码。


    public JsonPageResult(List<T> items, Page page) {
        super(items);

        this.total = page.getTotal();
        this.pageNo=page.getPageNum();
        this.pageSize = page.getPageSize();
        if(total > 0){
            int x1=(int) (this.total/this.pageSize);
            int x2=this.total%this.pageSize!=0?1:0;
            this.paginations =x1+x2;
        }else{
            this.paginations =0;
        }

    }

    public JsonPageResult(List<T> items, long total, int pageNo, int pageSize) {
        super(items);

        this.total = total;
        this.pageNo=pageNo;
        this.pageSize = pageSize;
        if(total > 0){
            int x1=(int) (this.total/this.pageSize);
            int x2=this.total%this.pageSize!=0?1:0;
            this.paginations =x1+x2;
        }else{
            this.paginations =0;
        }

    }

    public long getTotal() {
        return total;
    }

    public int getPageSize() {
        return pageSize;
    }

    public int getPaginations() {
        return paginations;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public void setPaginations(int paginations) {
        this.paginations = paginations;
    }
}